import QtQuick
import QtQuick.Layouts
import QtCharts

Rectangle {
    Layout.fillWidth: true
    Layout.fillHeight: true

    ChartView {
        id: chartView
        title: "日期坐标轴示例"
        titleFont.bold: true
        titleFont.pointSize: 14

        anchors.fill: parent
        antialiasing: true

        DateTimeAxis {
            id: valueAxisX
            min: new Date(2023, 0, 1)
            max: new Date(2023, 3, 1)
            format: "MMM yyyy"
            tickCount: 4
            titleText: "X Title"
        }

        ValueAxis {
            id: valueAxisY
            min: 0
            max: 16
            titleText: "Y Title"
        }

        LineSeries {
            name: "line"
            // 注意：JavaScript 的 Date 对象月份是从 0 开始的
            XYPoint { x: new Date(2023, 0, 1).getTime(); y: 10 }
            XYPoint { x: new Date(2023, 1, 1).getTime(); y: 15 }
            XYPoint { x: new Date(2023, 2, 1).getTime(); y: 12 }
            XYPoint { x: new Date(2023, 3, 1).getTime(); y: 18 }

            axisX: valueAxisX
            axisY: valueAxisY
        }
    }
}
